package de.ihk.datamanagment;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;

import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.Email;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;

@ManagedBean
public class Mailer implements Serializable {

	private static final long serialVersionUID = 1L;

	private Email mail;
	DefaultAuthenticator auth = new DefaultAuthenticator("domi@promolitor.de", "doo0loo");

	public Mailer() throws EmailException {
		mail = new SimpleEmail();
		mail.setHostName("smtp.1und1.de");
		mail.setSmtpPort(25);
		mail.setAuthenticator(auth);
		mail.setSSLOnConnect(false);
		mail.setFrom("domi@promolitor.de", "IHK-Aufgabensystem");
	}

	public void sendPassword(String email, String password) throws EmailException {
//		System.out.println("SENDPWDEBUG: \nEMAIL: "+email+"\nPassword: "+password);
		String msg = new String("Hallo " + email + ",\nIhr Password ist: " + password
				+ "\nMit freundlichen Grüßen\nIHK-Aufgabensystemadministrator");
		mail.setSubject("Password Wiederherstellung!");
		mail.setMsg(msg);
		mail.addTo(email);
		mail.send();
	}

	public Email getMail() {
		return mail;
	}

	public void setMail(Email mail) {
		this.mail = mail;
	}

}
